/**
 *  Copyright (C) 2006 zhangbo (freeeob@gmail.com)
 *
 *  This product is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU Lesser General Public License as published by
 *  the Free Software Foundation; either version 2.1 of the License, or
 *  (at your option) any later version.
 * 
 *  This product is distributed in the hope that it will be useful,
 *  but WITHOUT ANY WARRANTY; without even the implied warranty of
 *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *  GNU Lesser General Public License for more details.
 * 
 *  You should have received a copy of the GNU Lesser General Public License
 *  along with this library; if not, write to the Free Software
 *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA.
 *
 *  author:zhangbo
 *  Email:jsjava@gmail.com
 */

/**
 * Constructor
 */ 
function ChinaValidatorUtils(){
	this.jsjava_class="jsorg.eob.validator.ChinaValidatorUtils";
}

ChinaValidatorUtils.isChinese=function(value){
	var regx=/^[\u4e00-\u9fa5]+$/;
    return regx.test(value);
};

ChinaValidatorUtils.isIDCard=function(value){
	var regx=/^(\d{15}|\d{17}[\dx])$/;
    return regx.test(value);
};

ChinaValidatorUtils.isMobile=function(value){
	var regx=/^1[0-9][0-9]\d{8}$/;	
    return regx.test(value);
};

ChinaValidatorUtils.isOicq=function(value){
	var regx=/^[1-9][0-9]{4,}$/;
    return regx.test(value);
};

ChinaValidatorUtils.isPhone=function(value){
	var regx=/^\d{3,4}-\d{7,8}$/;
    return regx.test(value);
};

ChinaValidatorUtils.isZip=function(value){
	var regx=/^\d{6}$/;
    return regx.test(value);
};

ChinaValidatorUtils.isISBN=function(value){
	if(StringUtils.isBlank(value)){
		return false;
	}
	var len = value.length;
	var re13 = /^7-[\d|-]{9}-[\d|X]?$/;
	var re17 = /^978-7-[\d|-]{9}-[\d|X]?$/;
	var re = /^\d*-\d*$/;
	if(re13.exec(value)){
		var str = value.substr(2,9);	
		if(re.exec(str)){
			var sum = 0;
			var w = 0;
			for(var i=0;i<len-2;i++){
				var num = value.charAt(i);
				if(num!="-"){				
					sum += num * (10-w++);
				}
			}
			valid = 11-sum%11;
			if(valid==10) valid = 'X';
			if(valid==11) valid = 0;			
			if(valid == value.charAt(len-1)){
				return true;
			}
		}	
	}
	if(re17.exec(value)){
		var str = value.substr(6,9);
		if(re.exec(str)){
			var sum = 0;
			var w = 1;
			for(var i=0;i<len-2;i++){
				var num = value.charAt(i);
				if(num!="-"){
					sum += num * w;
					w = 4-w;
				}
			}
			valid = 10-sum%10;
			if(valid==10) valid = 0;
			if(valid == value.charAt(len-1)){
				return true;
			}
		}
	}
	return false;
};